public partial class QuerySche : Form
    {
        public QuerySche()
        {
            InitializeComponent();
        }

        private void QuerySche_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'stafScheDataSet.Staff' table. You can move, or remove it, as needed.
            this.staffTableAdapter.Fill(this.stafScheDataSet.Staff);
            // TODO: This line of code loads data into the 'stafScheDataSet.Staff' table. You can move, or remove it, as needed.
            this.staffTableAdapter.Fill(this.stafScheDataSet.Staff);
            // TODO: This line of code loads data into the 'stafScheDataSet.Schedule' table. You can move, or remove it, as needed.
            this.scheduleTableAdapter.Fill(this.stafScheDataSet.Schedule);
            DispSche(DateTime.Today);
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            DispSche(dateTimePicker1.Value.Date);
        }

        void DispSche(DateTime date)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name");
            for (int i = 0; i < 24; i++)
            {
                dt.Columns.Add("T" + i.ToString("00"));
            }
            string strFilter = "StartTime >= '"
                + date + "' and StartTime < '" + date.AddDays(1) + "'";
            DataRow[] dra = stafScheDataSet.Schedule.Select(strFilter, "staffID,StartTime");
            if (dra.Length > 0)
            {
                string strId = dra[0]["staffID"].ToString();
                string strTmp = strId;
                int iStartTime = DateTime.Parse(dra[0]["StartTime"].ToString()).Hour;
                decimal dHours = 0;
                decimal.TryParse(dra[0]["Hours"].ToString(), out dHours);
                DataRow dr = dt.NewRow();
                dr["Name"] = dra[0]["StaffID"].ToString();
                for (int i = 0; i < dHours; i++)
                {
                    dr[iStartTime + i + 1] = "W";
                }
                for (int i = 1; i < dra.Length; i++)
                {
                    strTmp = dra[i]["staffID"].ToString();
                    iStartTime = DateTime.Parse(dra[i]["StartTime"].ToString()).Hour;
                    dHours = 0;
                    decimal.TryParse(dra[0]["Hours"].ToString(), out dHours);
                    if (strTmp != strId)
                    {
                        dt.Rows.Add(dr);
                        dr = dt.NewRow();
                        strId = strTmp;
                        dr["Name"] = strId;
                        strTmp = strId;
                    }
                    for (int j = 0; j < dHours; j++)
                    {
                        dr[iStartTime + j + 1] = "W";
                    }
                }
                dt.Rows.Add(dr);
            }
            foreach (DataRow dr in dt.Rows)
            {
                dr["name"] = stafScheDataSet.Staff.Select("id="
                    + dr["name"].ToString())[0]["name"];
            }
            dataGridView1.DataSource = dt;
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            DispSche(dateTimePicker1.Value.Date);
        }
    }
